using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;


namespace Wagner.SharePoint.Utilities
{
	class SPDevTimerJobReceiver : SPFeatureReceiver
	{
		public override void FeatureActivated(SPFeatureReceiverProperties properties)
		{
			SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

			// Make sure the job isn't already registered.
			foreach (SPJobDefinition jobDef in webApp.JobDefinitions)
			{
				if (jobDef.Name == SPDevTimerJob.JobName)
					jobDef.Delete();
			}
			
			// Create the timer job.
			SPDevTimerJob job = new SPDevTimerJob(SPDevTimerJob.JobName, webApp);
			
			// Create a job to run once a day - by default.
			job.Schedule = SPDailySchedule.FromString("daily at 21:00:00");
			job.Update();			
		}

		public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
		{
			SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

			// Delete the job.
			foreach (SPJobDefinition job in webApp.JobDefinitions)
			{
				if (job.Name == SPDevTimerJob.JobName)
					job.Delete();
			}
		}

		public override void FeatureInstalled(SPFeatureReceiverProperties properties)
		{
		}

		public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
		{
		}

	}
}
